package com.huang.test;

import java.util.concurrent.TimeUnit;

public class t {
   static boolean flag=false;
    public static void main(String[] args) throws InterruptedException {


        new Thread(()->{
            while (!flag){
               System.out.println(flag);//打印也是加锁操作  保证率可见性
            }


        }).start();
        TimeUnit.SECONDS.sleep(2);

        new Thread(()->{
            flag=true;
        }).start();
    }
}
